<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>登陆</title>
    <link rel="stylesheet" href="css/reset.css">
    <style>
        .box {
            width: 1000px;
            margin: 100px auto;
            font-size: 15px;
            /* display: none; */
        }
        
        h2 {
            font-size: 30px;
            font-weight: 400;
            margin-bottom: 20px;
            line-height: 1.1;
        }
        
        .yhm input,
        .mim input {
            width: 98%;
            padding: 6px 12px;
            border-radius: 4px;
            border: 1px solid #ccc;
        }
        
        .yhm,
        .mim {
            font-weight: 700;
            margin: 20px 0;
        }
        
        .yhm label,
        .mim label {
            display: inline-block;
            margin-bottom: 5px;
        }
        
        hr {
            border: 0;
            border-bottom: 1px solid #ccc;
        }
        
        .mfdl {
            margin: 20px 0;
        }
        
        .mfdl {
            position: relative;
        }
        
        .mfdl label {
            margin-left: 20px;
        }
        
        .mfdl label input {
            position: absolute;
            margin-left: -20px;
            bottom: 3px;
        }
        
        button {
            padding: 6px 12px;
            background: #337ab7;
            border: 1px solid #2e6da4;
            color: #fff;
            border-radius: 5px;
            margin-right: 10px;
        }
        
        .box0 {
            width: 500px;
            margin: auto;
            background-color: #fff;
            overflow: hidden;
            border-radius: 5px;
            padding: 20px;
            font-size: 14px;
        }
        
        .quxiao {
            background: #fff;
            color: #000;
            border: 1px solid #ccc;
        }
        
        .zzc {
            width: 100%;
            height: 100%;
            background-color: #ccc;
        }
        
        html,
        body {
            width: 100%;
            height: 100%;
        }
        
        input,
        button {
            cursor: pointer;
        }
        
        button:hover {
            transform: scale(1.1);
        }
    </style>
</head>

<body>
    <div class="box">
        <h2>用户登陆</h2>
        <hr>
        <div class="yhm">
            <label for="yonghuming">用户名</label>
            <input type="text" id="yonghuming" placeholder="请输入用户名">
        </div>
        <div class="mim">
            <label for="mima">密码</label>
            <input type="password" id="mima" placeholder="请输入密码">
        </div>
        <div class="mfdl">
            <label for=""><input type="checkbox" id="fxk">30天内免登陆</label>
        </div>
        <button id="btn">登陆</button>
        <button id="btn2">注册</button>
    </div>

</body>
<script src="jquery.min.js"></script>
<script src="url.js"></script>
<script>
    $("#yonghuming").focus()

    $("#btn2").click(function() {
        location.href = `${path}/zhuce.html`;

    })

    $("#btn").click(function() {
        let username = $("#yonghuming").val();
        // console.log(username)
        let password = $("#mima").val();
        if (username && password) {
            $.ajax({
                url: `${path}/denglu`,
                data: {
                    username,
                    password
                },
                success(data) {

                    if (data === "2") {
                        alert("用户名或密码错误")
                    } else {

                        //判断复选框是否选中
                        if ($("#fxk")[0].checked) {
                            //现在的时间
                            let date = new Date();
                            //往后30天
                            date.setDate(date.getDate() + 30);
                            //cookie里存储

                            document.cookie = `userInfo=${JSON.stringify(data)};expires=${date}`
                            console.log(data)
                        }
                        sessionStorage.setItem("userInfo", JSON.stringify(data));
                        //登陆成功后跳转到app页面
                        location.href = `${path}/app.html`

                    }

                }
            })
        }
    })
    window.onkeydown = function(event) {

        if (event.keyCode === 13) {
            $("#btn").click()
        }

    }
</script>

</html>